﻿using System;
using DotNetApp.Toolkit.Requests;
using WinSource.Model;

namespace WinSource.Client
{
    internal class GetArticleDetailsRequest : Request<RequestArgs>
    {
        #region Fields

        private readonly Article _article;

        #endregion

        #region Constants

        private const string Url = "http://winsource.com/xmlrpc.php";

        #endregion

        #region Constructor

        public GetArticleDetailsRequest(Article article, Action<RequestArgs> callback = null)
            : base(callback)
        {
            _article = article;
        }

        #endregion

        #region Properties

        protected override string Link
        {
            get { return Url; }
        }

        protected override string Post
        {
            get
            {
                return string.Format("<?xml version='1.0' ?><methodCall><methodName>NeverstillPost</methodName><params><param><value><i4>{0}</i4></value></param></params></methodCall>", _article.Id);
            }
        }

        #endregion

        #region Request Overrides

        protected override void OnRequestCompleted(RequestResponseEventArgs requestResponseEventArgs)
        {
            if (!requestResponseEventArgs.Cancelled)
            {
                RequestArgs requestArgs = new RequestArgs(requestResponseEventArgs.Error == null, ResponseTimeInMs);

                if (requestResponseEventArgs.Error == null)
                {




                    InvokeCallback(requestArgs);
                }
            }
        }

        #endregion
    }
}
